<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Дмитрий
 * Date: 28.12.11
 * Time: 0:27
 * To change this template use File | Settings | File Templates.
 */
class AMessage extends CWidget
{

	private $_msgList = array();

	public function run(){
		if(Yii::app()->params['messages']!==null){
			$this->render('messages',array('messages'=>Yii::app()->params['messages']->getMessages()));
		}
	}

	public static function add($msg,$type='info'){
		if(gettype(Yii::app()->params['messages'])!='object'){
			Yii::app()->params['messages'] = new AMessage();
		}
		Yii::app()->params['messages']->addMessage($msg,$type);
	}

	public function addMessage($msg,$type='info'){
		if(gettype($msg)=='string'){
			$this->_msgList[$type][] = $msg;
		}elseif(gettype($msg)=='array'){
			foreach($msg AS $v){
				$this->addMessage($v,$type);
			}
		}
	}

	public function getMessages(){
		return $this->_msgList;
	}
}